package com.scut.wordskillerbackend.service;

import com.scut.wordskillerbackend.mapper.UserArchiveMapper;
import com.scut.wordskillerbackend.po.User;
import com.scut.wordskillerbackend.po.UserArchive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserArchiveService {
    @Autowired
    private UserArchiveMapper userArchiveMapper;
    @Autowired
    private UserService userService;

    public boolean updateArchiveService(String content, String authorization) {
        User user = userService.selectUserByToken(authorization);
        if (user == null) return false;
        UserArchive userArchive = new UserArchive(user.getId(), content);
        if (userArchiveMapper.selectById(user.getId()) == null) {
            System.out.println("AT1");
            return userArchiveMapper.insert(userArchive) == 1;
        } else {
            System.out.println("AT2");
            return userArchiveMapper.updateById(userArchive) == 1;
        }
    }
}
